<template>
  <Layout class="p-5 bg-white">
    <Form :label-width="80">
      <FormItem class="w-50" label="回访描述">
        <Input
          type="textarea"
          v-model="backview.des"
          placeholder="请输入回访描述"
        ></Input>
      </FormItem>

      <FormItem class="w-50" label="回访人">
        <Input v-model="backview.autor" placeholder="请输入回访人"></Input>
      </FormItem>

      <FormItem class="w-50" label="回访日期">
        <Input v-model="backview.dateTime" placeholder="请输入回访日期"></Input>
      </FormItem>

      <FormItem class="w-50" label="回访方式">
        <Input v-model="backview.method" placeholder="请输入回访方式"></Input>
      </FormItem>

      <FormItem class="w-50" label="回访结果">
        <Input
          type="textarea"
          v-model="backview.result"
          placeholder="回访结果"
        ></Input>
      </FormItem>

      <FormItem class="w-50" label="回访类型">
        <Input v-model="backview.type" placeholder="回访类型"></Input>
      </FormItem>

      <FormItem class="w-50" label="回访阶段">
        <Select @on-change="changeP">
          <!--XX-->
          <Option v-for="fStage in allStages">{{ fStage.name }}</Option>
        </Select>
      </FormItem>

      <FormItem class="text-right">
        <Button @click="submit" type="primary">提交</Button>
        <Button @click="cancel" class="ml-2">取消</Button>
      </FormItem>
    </Form>
  </Layout>
</template>

<script>
export default {
  data() {
    return {
      backview: {
        id: null,
        type: '',
        autor: null,
        des: '',
        result: '',
        dateTime: '',
        state: '',
        method: '',
        cu: null,
        ct: '',
        uu: null,
        ut: '',
      },
      allStages: [], //XX
    }
  },
  methods: {
    changeP: function(selectedPermissionId) {
      if (selectedPermissionId === 0) {
        this.$data.permission.path = ''
      }
    },
    submit: function() {
      let self = this

      if (this.$data.permission.name.length === 0) {
        this.message.error('请输入权限名称')
        return
      }

      if (this.$data.permission.pId !== 0) {
        if (this.$data.permission.path.length === 0) {
          this.message.error('请输入权限路径')
          return
        }
      }

      this.http
        .post({
          url: '/permission/info',
          param: self.$data.permission,
        })
        .then((data) => {
          self.message.info('添加成功')
          self.$tabs.close()
        })
    },
    cancel: function() {
      this.$tabs.close()
    },
    init: function() {
      let self = this
      this.http
        .get({
          url: '/backview/all', //--->做选择具体阶段的下拉框
        })
        .then((data) => {
          //then--------------
          self.$data.allStages.push({
            //XX
            id: 0,
            name: '线索阶段',
          })
          for (let index in data) {
            let allStages = {}
            allStages.name = data[index].name
            self.$data.allStages.push(allStages) //XX
          }
        }) //then--------------
    },
  },
  created: function() {
    this.init()
  },
}
</script>

<style></style>
